home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / CP_Utils.c < prev    next >
Text File  |  1995-11-24  |  3KB  |  79 lines

  1. /*
  2.     Version History:
  3.         1.01    11/24/95
  4.             Changed prototypes to use CP_Data's cross-platform data types.
  5. */
  6.  
  7. #include "CP_Utils.h"
  8.  
  9. void CP_SetRect(CP_Rect *destR, CP_Long left, CP_Long top, CP_Long right, CP_Long bottom) {
  10.     destR->left        = left;
  11.     destR->top        = top;
  12.     destR->right    = right;
  13.     destR->bottom    = bottom;
  14. } // END CP_SetRect
  15.  
  16. // ---------------------------------------------------------------------------
  17.  
  18. void CP_OffsetRect(CP_Rect *destR, CP_Long offsetH, CP_Long offsetV) {
  19.     destR->top        += offsetV;
  20.     destR->bottom    += offsetV;
  21.     destR->right    += offsetH;
  22.     destR->left        += offsetH;
  23. } // END CP_OffsetRect
  24.  
  25. // ---------------------------------------------------------------------------
  26.  
  27. void CP_UnionRect(const CP_Rect *rectA, const CP_Rect *rectB, CP_Rect *unionR) {
  28.     unionR->top        = CP_MIN(rectA->top, rectB->top);
  29.     unionR->left    = CP_MIN(rectA->left, rectB->left);
  30.     unionR->bottom    = CP_MAX(rectA->bottom, rectB->bottom);
  31.     unionR->right    = CP_MAX(rectA->right, rectB->bottom);
  32. } // END CP_UnionRect
  33.  
  34. // ---------------------------------------------------------------------------
  35.  
  36. void CP_CenterRect(CP_Rect *innerRect, const CP_Rect *outerRect) {
  37.     CP_Long outerRectWidth    = outerRect->right    - outerRect->left;
  38.     CP_Long outerRectHeight    = outerRect->bottom    - outerRect->top;
  39.     CP_Long innerRectWidth    = innerRect->right    - innerRect->left;
  40.     CP_Long innerRectHeight    = innerRect->bottom    - innerRect->top;
  41.     CP_Long hDiff            = (outerRectWidth - innerRectWidth) / 2;
  42.     CP_Long vDiff            = (outerRectHeight - innerRectHeight) / 2;
  43.     innerRect->left        = outerRect->left + hDiff;
  44.     innerRect->right    = innerRect->left + innerRectWidth;
  45.     innerRect->top        = outerRect->top + vDiff;
  46.     innerRect->bottom    = innerRect->top + innerRectHeight;
  47. } // END CP_CenterRect
  48.  
  49. // ---------------------------------------------------------------------------
  50.  
  51. void CP_MoveRectTo(CP_Rect *theRect, CP_Long destLeft, CP_Long destTop) {
  52.     CP_Long width = theRect->right - theRect->left;
  53.     CP_Long height = theRect->bottom - theRect->top;
  54.     theRect->left = destLeft;
  55.     theRect->top = destTop;
  56.     theRect->right = theRect->left + width;
  57.     theRect->bottom = theRect->top + height;
  58. } // END MoveRectTo
  59.  
  60. // ---------------------------------------------------------------------------
  61.  
  62. void CP_OffsetPoint(CP_Point *pt, CP_Long offsetH, CP_Long offsetV) {
  63.     pt->hv.h += offsetH;
  64.     pt->hv.v += offsetV;
  65. } // END CP_OffsetPoint
  66.  
  67. // ---------------------------------------------------------------------------
  68.  
  69. short CP_PointInRect(const CP_Point *pt, const CP_Rect *rect) {
  70.     if ((pt->hv.h >= rect->left) &&
  71.         (pt->hv.h <= rect->right) &&
  72.         (pt->hv.v >= rect->top) &&
  73.         (pt->hv.v <= rect->bottom))
  74.         return(TRUE);
  75.     else
  76.         return(FALSE);
  77. } // END CP_PointInRect
  78.  
  79. // ---------------------------------------------------------------------------